package com.ems.sys.controller;

import com.ems.sys.pojo.EmsQuit;
import com.ems.sys.service.EmsQuitService;
import com.github.pagehelper.PageInfo;
import com.ems.entity.Result;
import com.ems.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/sys/emsQuit")
//@CrossOrigin
public class EmsQuitController {

    @Autowired
    private EmsQuitService emsQuitService;

    /***
     * EmsQuit分页条件搜索实现
     * @param emsQuit
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  EmsQuit emsQuit, @PathVariable  int page, @PathVariable  int size){
        //调用EmsQuitService实现分页条件查询EmsQuit
        PageInfo<EmsQuit> pageInfo = emsQuitService.findPage(emsQuit, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * EmsQuit分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用EmsQuitService实现分页查询EmsQuit
        PageInfo<EmsQuit> pageInfo = emsQuitService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param emsQuit
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<EmsQuit>> findList(@RequestBody(required = false)  EmsQuit emsQuit){
        //调用EmsQuitService实现条件查询EmsQuit
        List<EmsQuit> list = emsQuitService.findList(emsQuit);
        return new Result<List<EmsQuit>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable String id){
        //调用EmsQuitService实现根据主键删除
        emsQuitService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改EmsQuit数据
     * @param emsQuit
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  EmsQuit emsQuit,@PathVariable String id){
        //设置主键值
        emsQuit.setEId(id);
        //调用EmsQuitService实现修改EmsQuit
        emsQuitService.update(emsQuit);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增EmsQuit数据
     * @param emsQuit
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   EmsQuit emsQuit){
        //调用EmsQuitService实现添加EmsQuit
        emsQuitService.add(emsQuit);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询EmsQuit数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<EmsQuit> findById(@PathVariable String id){
        //调用EmsQuitService实现根据主键查询EmsQuit
        EmsQuit emsQuit = emsQuitService.findById(id);
        return new Result<EmsQuit>(true,StatusCode.OK,"查询成功",emsQuit);
    }

    /***
     * 查询EmsQuit全部数据
     * @return
     */
    @GetMapping
    public Result<List<EmsQuit>> findAll(){
        //调用EmsQuitService实现查询所有EmsQuit
        List<EmsQuit> list = emsQuitService.findAll();
        return new Result<List<EmsQuit>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
